Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api enhancement to support optional collection_class parameter #13845

Merged
merged 2 commits into from
Feb 10, 2017

Conversation

abellotti
Copy link
Member

@abellotti abellotti commented Feb 9, 2017

  • Allows subclassing any collection
  • specified via ?collection_class=
    i.e. GET /api/vms?collection_class=ManageIQ::Providers::CloudManager::Vm
  • Updated CLI to support --collection-class=

https://www.pivotaltracker.com/story/show/139478269

- Allows subclassing any collection
- specified via ?collection_class=<class>
  i.e. GET /api/vms?collection_class=ManageIQ::Providers::CloudManager::Vm
- Updated CLI to support --collection-class=<class>
@abellotti
Copy link
Member Author

/cc @Fryguy @jntullo @bdunne as discussed in our meeting.

Implemented it generically, so it would work with any collection.

Marked as WIP, needing specs.

@Fryguy
Copy link
Member

Fryguy commented Feb 9, 2017

cc @gtanzillo

# If it is the collection's class, then we're good to go as is.
return if param_klass == collection_klass

if param_klass < collection_klass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can do <= and just collapse this conditional with the one above.

return unless param.present?

begin
param_klass = param.constantize
Copy link
Member

@Fryguy Fryguy Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer safe_constantize over constantize for this case. and don't rescue (instead just check for nil).

@Fryguy
Copy link
Member

Fryguy commented Feb 9, 2017

@abellotti Want would a caller look like (i.e. what would a get and a post look like)?

Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Cool!

- Simplified validate_collection_class logic
- Leveraging descendants to keep brakeman happy
- Added rspecs
@miq-bot
Copy link
Member

miq-bot commented Feb 10, 2017

Checked commits abellotti/manageiq@97df523~...dd8fd54 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks good. 🍪

klass = collection_class(@req.collection)
return if param == klass.name

param_klass = klass.descendants.detect { |sub_klass| param == sub_klass.name }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I like that much better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had no choice :) brakeman wasn't happy with constantize with user specified parameter. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's usually a big no-no, which was why I was commenting. Glad you found a much nicer alternative!

@abellotti abellotti removed the wip label Feb 10, 2017
@abellotti abellotti changed the title [WIP] Api enhancement to support optional collection_class parameter Api enhancement to support optional collection_class parameter Feb 10, 2017
@Fryguy Fryguy merged commit 242d104 into ManageIQ:master Feb 10, 2017
@Fryguy Fryguy added this to the Sprint 54 Ending Feb 13, 2017 milestone Feb 10, 2017
@abellotti abellotti deleted the api_collection_class branch February 15, 2017 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants